{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "501af995",
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "先用股票平均值与标准差将价格标准化\n",
    "\n",
    "import sys\n",
    "sys.path.append('..')\n",
    "\n",
    "from common.tushareHelper import tushare_helper as ts\n",
    "'''\n",
    "import tushare as ts\n",
    "import pandas as pd\n",
    "from dateutil.parser import parse\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "plt.rcParams['font.sans-serif'] = ['SimHei']\n",
    "plt.rcParams['axes.unicode_minus']=False # 负号问题\n",
    "pd.options.mode.chained_assignment = None\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "b531c00e",
   "metadata": {},
   "outputs": [],
   "source": [
    "pro = ts.pro_api(\"0ba8feef618e5db7b1ebb65538fe51e4aef69fb3cbf709d44128f313\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "3003e40d",
   "metadata": {},
   "outputs": [],
   "source": [
    "def init_df(df):\n",
    "    df['trade_date']= df['trade_date'].apply(parse)\n",
    "    df = df.set_index('trade_date')\n",
    "    return df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "22dc7228",
   "metadata": {},
   "outputs": [],
   "source": [
    "code_sa = 'SA2209.ZCE'\n",
    "code_fg = 'FG2209.ZCE'\n",
    "startdate = '20210101'\n",
    "enddate = '20220520'\n",
    "df_sa = init_df( pro.query(\"fut_daily\", ts_code=code_sa, start_date=startdate, end_date=enddate))\n",
    "df_fg = init_df(pro.query(\"fut_daily\", ts_code=code_fg, start_date=startdate, end_date=enddate))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "0bcd3d4b",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code_x</th>\n",
       "      <th>pre_close_x</th>\n",
       "      <th>pre_settle_x</th>\n",
       "      <th>open_x</th>\n",
       "      <th>high_x</th>\n",
       "      <th>low_x</th>\n",
       "      <th>close_x</th>\n",
       "      <th>settle_x</th>\n",
       "      <th>change1_x</th>\n",
       "      <th>change2_x</th>\n",
       "      <th>...</th>\n",
       "      <th>high_y</th>\n",
       "      <th>low_y</th>\n",
       "      <th>close_y</th>\n",
       "      <th>settle_y</th>\n",
       "      <th>change1_y</th>\n",
       "      <th>change2_y</th>\n",
       "      <th>vol_y</th>\n",
       "      <th>amount_y</th>\n",
       "      <th>oi_y</th>\n",
       "      <th>oi_chg_y</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>trade_date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-05-10</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>2928.0</td>\n",
       "      <td>2963.0</td>\n",
       "      <td>2900.0</td>\n",
       "      <td>2916.0</td>\n",
       "      <td>2700.0</td>\n",
       "      <td>2778.0</td>\n",
       "      <td>2798.0</td>\n",
       "      <td>-185.0</td>\n",
       "      <td>-165.0</td>\n",
       "      <td>...</td>\n",
       "      <td>1830.0</td>\n",
       "      <td>1724.0</td>\n",
       "      <td>1791.0</td>\n",
       "      <td>1778.0</td>\n",
       "      <td>-43.0</td>\n",
       "      <td>-56.0</td>\n",
       "      <td>1567171.0</td>\n",
       "      <td>5573066.71</td>\n",
       "      <td>610684.0</td>\n",
       "      <td>-53923.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-05-09</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>2982.0</td>\n",
       "      <td>3026.0</td>\n",
       "      <td>2982.0</td>\n",
       "      <td>3016.0</td>\n",
       "      <td>2917.0</td>\n",
       "      <td>2928.0</td>\n",
       "      <td>2963.0</td>\n",
       "      <td>-98.0</td>\n",
       "      <td>-63.0</td>\n",
       "      <td>...</td>\n",
       "      <td>1862.0</td>\n",
       "      <td>1809.0</td>\n",
       "      <td>1825.0</td>\n",
       "      <td>1834.0</td>\n",
       "      <td>-53.0</td>\n",
       "      <td>-44.0</td>\n",
       "      <td>953086.0</td>\n",
       "      <td>3495082.01</td>\n",
       "      <td>664607.0</td>\n",
       "      <td>26232.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-05-06</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>3061.0</td>\n",
       "      <td>3005.0</td>\n",
       "      <td>3067.0</td>\n",
       "      <td>3077.0</td>\n",
       "      <td>2977.0</td>\n",
       "      <td>2982.0</td>\n",
       "      <td>3026.0</td>\n",
       "      <td>-23.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>...</td>\n",
       "      <td>1899.0</td>\n",
       "      <td>1841.0</td>\n",
       "      <td>1855.0</td>\n",
       "      <td>1878.0</td>\n",
       "      <td>-32.0</td>\n",
       "      <td>-9.0</td>\n",
       "      <td>839975.0</td>\n",
       "      <td>3154653.94</td>\n",
       "      <td>638375.0</td>\n",
       "      <td>14684.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-05-05</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>3004.0</td>\n",
       "      <td>2985.0</td>\n",
       "      <td>2990.0</td>\n",
       "      <td>3073.0</td>\n",
       "      <td>2923.0</td>\n",
       "      <td>3061.0</td>\n",
       "      <td>3005.0</td>\n",
       "      <td>76.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>...</td>\n",
       "      <td>1922.0</td>\n",
       "      <td>1858.0</td>\n",
       "      <td>1885.0</td>\n",
       "      <td>1887.0</td>\n",
       "      <td>34.0</td>\n",
       "      <td>36.0</td>\n",
       "      <td>758731.0</td>\n",
       "      <td>2863699.81</td>\n",
       "      <td>623691.0</td>\n",
       "      <td>38469.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-29</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>3012.0</td>\n",
       "      <td>2972.0</td>\n",
       "      <td>3010.0</td>\n",
       "      <td>3028.0</td>\n",
       "      <td>2954.0</td>\n",
       "      <td>3004.0</td>\n",
       "      <td>2985.0</td>\n",
       "      <td>32.0</td>\n",
       "      <td>13.0</td>\n",
       "      <td>...</td>\n",
       "      <td>1885.0</td>\n",
       "      <td>1824.0</td>\n",
       "      <td>1882.0</td>\n",
       "      <td>1851.0</td>\n",
       "      <td>42.0</td>\n",
       "      <td>11.0</td>\n",
       "      <td>935674.0</td>\n",
       "      <td>3464627.48</td>\n",
       "      <td>585222.0</td>\n",
       "      <td>-35552.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 28 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             ts_code_x  pre_close_x  pre_settle_x  open_x  high_x   low_x  \\\n",
       "trade_date                                                                  \n",
       "2022-05-10  SA2209.ZCE       2928.0        2963.0  2900.0  2916.0  2700.0   \n",
       "2022-05-09  SA2209.ZCE       2982.0        3026.0  2982.0  3016.0  2917.0   \n",
       "2022-05-06  SA2209.ZCE       3061.0        3005.0  3067.0  3077.0  2977.0   \n",
       "2022-05-05  SA2209.ZCE       3004.0        2985.0  2990.0  3073.0  2923.0   \n",
       "2022-04-29  SA2209.ZCE       3012.0        2972.0  3010.0  3028.0  2954.0   \n",
       "\n",
       "            close_x  settle_x  change1_x  change2_x  ...  high_y   low_y  \\\n",
       "trade_date                                           ...                   \n",
       "2022-05-10   2778.0    2798.0     -185.0     -165.0  ...  1830.0  1724.0   \n",
       "2022-05-09   2928.0    2963.0      -98.0      -63.0  ...  1862.0  1809.0   \n",
       "2022-05-06   2982.0    3026.0      -23.0       21.0  ...  1899.0  1841.0   \n",
       "2022-05-05   3061.0    3005.0       76.0       20.0  ...  1922.0  1858.0   \n",
       "2022-04-29   3004.0    2985.0       32.0       13.0  ...  1885.0  1824.0   \n",
       "\n",
       "            close_y  settle_y change1_y  change2_y      vol_y    amount_y  \\\n",
       "trade_date                                                                  \n",
       "2022-05-10   1791.0    1778.0     -43.0      -56.0  1567171.0  5573066.71   \n",
       "2022-05-09   1825.0    1834.0     -53.0      -44.0   953086.0  3495082.01   \n",
       "2022-05-06   1855.0    1878.0     -32.0       -9.0   839975.0  3154653.94   \n",
       "2022-05-05   1885.0    1887.0      34.0       36.0   758731.0  2863699.81   \n",
       "2022-04-29   1882.0    1851.0      42.0       11.0   935674.0  3464627.48   \n",
       "\n",
       "                oi_y  oi_chg_y  \n",
       "trade_date                      \n",
       "2022-05-10  610684.0  -53923.0  \n",
       "2022-05-09  664607.0   26232.0  \n",
       "2022-05-06  638375.0   14684.0  \n",
       "2022-05-05  623691.0   38469.0  \n",
       "2022-04-29  585222.0  -35552.0  \n",
       "\n",
       "[5 rows x 28 columns]"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_all = pd.merge(df_sa,df_fg, on='trade_date', how='left')\n",
    "# pd.concat([paf, pbf], axis=1)\n",
    "df_all.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "568ad4d2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code_x</th>\n",
       "      <th>close_x</th>\n",
       "      <th>ts_code_y</th>\n",
       "      <th>close_y</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>trade_date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-05-10</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>2778.0</td>\n",
       "      <td>FG2209.ZCE</td>\n",
       "      <td>1791.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-05-09</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>2928.0</td>\n",
       "      <td>FG2209.ZCE</td>\n",
       "      <td>1825.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-05-06</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>2982.0</td>\n",
       "      <td>FG2209.ZCE</td>\n",
       "      <td>1855.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-05-05</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>3061.0</td>\n",
       "      <td>FG2209.ZCE</td>\n",
       "      <td>1885.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-29</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>3004.0</td>\n",
       "      <td>FG2209.ZCE</td>\n",
       "      <td>1882.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-09-23</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>2982.0</td>\n",
       "      <td>FG2209.ZCE</td>\n",
       "      <td>2049.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-09-22</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>2891.0</td>\n",
       "      <td>FG2209.ZCE</td>\n",
       "      <td>1985.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-09-17</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>2818.0</td>\n",
       "      <td>FG2209.ZCE</td>\n",
       "      <td>2010.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-09-16</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>3052.0</td>\n",
       "      <td>FG2209.ZCE</td>\n",
       "      <td>2078.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-09-15</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>2968.0</td>\n",
       "      <td>FG2209.ZCE</td>\n",
       "      <td>2055.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>152 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             ts_code_x  close_x   ts_code_y  close_y\n",
       "trade_date                                          \n",
       "2022-05-10  SA2209.ZCE   2778.0  FG2209.ZCE   1791.0\n",
       "2022-05-09  SA2209.ZCE   2928.0  FG2209.ZCE   1825.0\n",
       "2022-05-06  SA2209.ZCE   2982.0  FG2209.ZCE   1855.0\n",
       "2022-05-05  SA2209.ZCE   3061.0  FG2209.ZCE   1885.0\n",
       "2022-04-29  SA2209.ZCE   3004.0  FG2209.ZCE   1882.0\n",
       "...                ...      ...         ...      ...\n",
       "2021-09-23  SA2209.ZCE   2982.0  FG2209.ZCE   2049.0\n",
       "2021-09-22  SA2209.ZCE   2891.0  FG2209.ZCE   1985.0\n",
       "2021-09-17  SA2209.ZCE   2818.0  FG2209.ZCE   2010.0\n",
       "2021-09-16  SA2209.ZCE   3052.0  FG2209.ZCE   2078.0\n",
       "2021-09-15  SA2209.ZCE   2968.0  FG2209.ZCE   2055.0\n",
       "\n",
       "[152 rows x 4 columns]"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "columns_filter = ['ts_code_x', 'close_x', 'ts_code_y','close_y']\n",
    "df_filter = df_all[]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "7b2dfb53",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code</th>\n",
       "      <th>pre_close</th>\n",
       "      <th>pre_settle</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>settle</th>\n",
       "      <th>change1</th>\n",
       "      <th>change2</th>\n",
       "      <th>vol</th>\n",
       "      <th>amount</th>\n",
       "      <th>oi</th>\n",
       "      <th>oi_chg</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>trade_date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-05-10</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>2928.0</td>\n",
       "      <td>2963.0</td>\n",
       "      <td>2900.0</td>\n",
       "      <td>2916.0</td>\n",
       "      <td>2700.0</td>\n",
       "      <td>2778.0</td>\n",
       "      <td>2798.0</td>\n",
       "      <td>-185.0</td>\n",
       "      <td>-165.0</td>\n",
       "      <td>1704663.0</td>\n",
       "      <td>9540284.91</td>\n",
       "      <td>632528.0</td>\n",
       "      <td>-15909.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-05-09</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>2982.0</td>\n",
       "      <td>3026.0</td>\n",
       "      <td>2982.0</td>\n",
       "      <td>3016.0</td>\n",
       "      <td>2917.0</td>\n",
       "      <td>2928.0</td>\n",
       "      <td>2963.0</td>\n",
       "      <td>-98.0</td>\n",
       "      <td>-63.0</td>\n",
       "      <td>1280886.0</td>\n",
       "      <td>7589364.87</td>\n",
       "      <td>648437.0</td>\n",
       "      <td>47147.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-05-06</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>3061.0</td>\n",
       "      <td>3005.0</td>\n",
       "      <td>3067.0</td>\n",
       "      <td>3077.0</td>\n",
       "      <td>2977.0</td>\n",
       "      <td>2982.0</td>\n",
       "      <td>3026.0</td>\n",
       "      <td>-23.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>994963.0</td>\n",
       "      <td>6020699.07</td>\n",
       "      <td>601290.0</td>\n",
       "      <td>-6371.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-05-05</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>3004.0</td>\n",
       "      <td>2985.0</td>\n",
       "      <td>2990.0</td>\n",
       "      <td>3073.0</td>\n",
       "      <td>2923.0</td>\n",
       "      <td>3061.0</td>\n",
       "      <td>3005.0</td>\n",
       "      <td>76.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>879241.0</td>\n",
       "      <td>5284072.38</td>\n",
       "      <td>607661.0</td>\n",
       "      <td>75798.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-29</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>3012.0</td>\n",
       "      <td>2972.0</td>\n",
       "      <td>3010.0</td>\n",
       "      <td>3028.0</td>\n",
       "      <td>2954.0</td>\n",
       "      <td>3004.0</td>\n",
       "      <td>2985.0</td>\n",
       "      <td>32.0</td>\n",
       "      <td>13.0</td>\n",
       "      <td>899772.0</td>\n",
       "      <td>5371563.62</td>\n",
       "      <td>531863.0</td>\n",
       "      <td>-44269.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               ts_code  pre_close  pre_settle    open    high     low   close  \\\n",
       "trade_date                                                                      \n",
       "2022-05-10  SA2209.ZCE     2928.0      2963.0  2900.0  2916.0  2700.0  2778.0   \n",
       "2022-05-09  SA2209.ZCE     2982.0      3026.0  2982.0  3016.0  2917.0  2928.0   \n",
       "2022-05-06  SA2209.ZCE     3061.0      3005.0  3067.0  3077.0  2977.0  2982.0   \n",
       "2022-05-05  SA2209.ZCE     3004.0      2985.0  2990.0  3073.0  2923.0  3061.0   \n",
       "2022-04-29  SA2209.ZCE     3012.0      2972.0  3010.0  3028.0  2954.0  3004.0   \n",
       "\n",
       "            settle  change1  change2        vol      amount        oi   oi_chg  \n",
       "trade_date                                                                      \n",
       "2022-05-10  2798.0   -185.0   -165.0  1704663.0  9540284.91  632528.0 -15909.0  \n",
       "2022-05-09  2963.0    -98.0    -63.0  1280886.0  7589364.87  648437.0  47147.0  \n",
       "2022-05-06  3026.0    -23.0     21.0   994963.0  6020699.07  601290.0  -6371.0  \n",
       "2022-05-05  3005.0     76.0     20.0   879241.0  5284072.38  607661.0  75798.0  \n",
       "2022-04-29  2985.0     32.0     13.0   899772.0  5371563.62  531863.0 -44269.0  "
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_sa = init_df(df_sa)\n",
    "df_sa.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "1302950a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code_x</th>\n",
       "      <th>close_x</th>\n",
       "      <th>ts_code_y</th>\n",
       "      <th>close_y</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>trade_date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-05-10</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>2778.0</td>\n",
       "      <td>FG2209.ZCE</td>\n",
       "      <td>1791.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-05-09</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>2928.0</td>\n",
       "      <td>FG2209.ZCE</td>\n",
       "      <td>1825.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-05-06</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>2982.0</td>\n",
       "      <td>FG2209.ZCE</td>\n",
       "      <td>1855.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-05-05</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>3061.0</td>\n",
       "      <td>FG2209.ZCE</td>\n",
       "      <td>1885.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-29</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>3004.0</td>\n",
       "      <td>FG2209.ZCE</td>\n",
       "      <td>1882.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             ts_code_x  close_x   ts_code_y  close_y\n",
       "trade_date                                          \n",
       "2022-05-10  SA2209.ZCE   2778.0  FG2209.ZCE   1791.0\n",
       "2022-05-09  SA2209.ZCE   2928.0  FG2209.ZCE   1825.0\n",
       "2022-05-06  SA2209.ZCE   2982.0  FG2209.ZCE   1855.0\n",
       "2022-05-05  SA2209.ZCE   3061.0  FG2209.ZCE   1885.0\n",
       "2022-04-29  SA2209.ZCE   3004.0  FG2209.ZCE   1882.0"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_filter.head()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "2e6cfe7b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code_x</th>\n",
       "      <th>close_x</th>\n",
       "      <th>ts_code_y</th>\n",
       "      <th>close_y</th>\n",
       "      <th>x_return</th>\n",
       "      <th>y_return</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>trade_date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-05-10</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>2778.0</td>\n",
       "      <td>FG2209.ZCE</td>\n",
       "      <td>1791.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-05-09</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>2928.0</td>\n",
       "      <td>FG2209.ZCE</td>\n",
       "      <td>1825.0</td>\n",
       "      <td>0.053996</td>\n",
       "      <td>0.018984</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-05-06</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>2982.0</td>\n",
       "      <td>FG2209.ZCE</td>\n",
       "      <td>1855.0</td>\n",
       "      <td>0.018443</td>\n",
       "      <td>0.016438</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-05-05</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>3061.0</td>\n",
       "      <td>FG2209.ZCE</td>\n",
       "      <td>1885.0</td>\n",
       "      <td>0.026492</td>\n",
       "      <td>0.016173</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-29</th>\n",
       "      <td>SA2209.ZCE</td>\n",
       "      <td>3004.0</td>\n",
       "      <td>FG2209.ZCE</td>\n",
       "      <td>1882.0</td>\n",
       "      <td>-0.018621</td>\n",
       "      <td>-0.001592</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             ts_code_x  close_x   ts_code_y  close_y  x_return  y_return\n",
       "trade_date                                                              \n",
       "2022-05-10  SA2209.ZCE   2778.0  FG2209.ZCE   1791.0       NaN       NaN\n",
       "2022-05-09  SA2209.ZCE   2928.0  FG2209.ZCE   1825.0  0.053996  0.018984\n",
       "2022-05-06  SA2209.ZCE   2982.0  FG2209.ZCE   1855.0  0.018443  0.016438\n",
       "2022-05-05  SA2209.ZCE   3061.0  FG2209.ZCE   1885.0  0.026492  0.016173\n",
       "2022-04-29  SA2209.ZCE   3004.0  FG2209.ZCE   1882.0 -0.018621 -0.001592"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_dest = df_filter\n",
    "df_dest['x_return'] =(df_dest['close_x'] - df_dest['close_x'].shift(1)) / df_dest['close_x'].shift(1)\n",
    "df_dest['y_return'] =(df_dest['close_y'] - df_dest['close_y'].shift(1)) / df_dest['close_y'].shift(1)\n",
    "df_dest.head()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "53805e31",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0, 0.5, 'fg')"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYkAAAESCAYAAAAIfCk9AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAmrElEQVR4nO3df5BdZZ3n8fc3zQ10gtBh6I2VXgI4w4Yfy4TeyWgkoElmMCLL2AYdUEerppaNM+Wyo2V1GXaiApXVjIy/FdZonKodUAmgPbDgADstA8aN2jFkEFfKcQk4bVHGISEVEk2TfPePe2/69u1zzj3n3vPr3v68qrpobj/33Ofe7pzvOd/neb6PuTsiIiJB5hXdARERKS8FCR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+vMYkIQdkDxAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(df_dest['x_return'], df_dest['y_return'])\n",
    "plt.title('散点图')\n",
    "plt.xlabel('sa')\n",
    "plt.ylabel('fg')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "10805331",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.7783352207626729"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_dest.x_return.corr(df_dest.y_return)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e1cdb072",
   "metadata": {},
   "outputs": [],
   "source": [
    "def SSD(priceX, priceY):\n",
    "    if priceX is None or priceY is None:\n",
    "        print('缺少价格序列')\n",
    "        return\n",
    "    \n",
    "    returnX = (priceX - priceX.shift(1)) / priceX.shift(1)[1:]\n",
    "    returnY = (priceY - priceY.shift(1)) / priceY.shift(1)[1:]\n",
    "    \n",
    "    standX = (returnX + 1).cumprod()\n",
    "    standY = (returnY + 1).comprod()\n",
    "    \n",
    "    SSD = np.sum((standX - standY) ** 2)\n",
    "    return SSD\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f77dd89f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
